package com.yaoxuguang.concurrence.wait_notify.thread_commumication_pipeline;

import com.yaoxuguang.concurrence.wait_notify.notify.ThreadWait;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.wait_notify.thread_commumication_pipeline
 * @Description: 测试利用管道进行线程之间的通讯
 * @date 2018年12月24日11:09
 */
public class Run {
    public static void main(String[] args) {
        try {
            WriteData writeData = new WriteData();
            ReadData readData = new ReadData();

            PipedWriter pipedWriter = new PipedWriter();
            PipedReader pipedReader = new PipedReader();
//            pipedWriter.connect(pipedReader);
            pipedReader.connect(pipedWriter);

            ThreadRead threadRead = new ThreadRead(readData,pipedReader);
            threadRead.start();
            Thread.sleep(3000);

            ThreadWrite threadWrite = new ThreadWrite(writeData,pipedWriter);
            threadWrite.start();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
